<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-select.css">
    <link rel="stylesheet" href="css/datepicker.css">
    <link rel="stylesheet" href="css/unionboostrap.css">
    <link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="css/chosen.css">
    <link rel="stylesheet" href="css/commonSupport.css">
    <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
    <link rel="stylesheet" href="css/metro.css">
    <link rel="stylesheet" href="css/jquery.gritter.css">
    <link rel="stylesheet" href="css/font-awesome.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/style_responsive.css">
    <link rel="stylesheet" href="css/TopMenu.css">
    <link rel="stylesheet" href="css/windowbox.css">

    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/bootstrap-select.js"></script>
    <script src="js/bootstrap-dropdown.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-datetimepicker.js"></script>
    <script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
    <!-- 引入 echarts.js -->
    <script src="js/echarts.js"></script>
    <script src="js/china.js"></script>
    <script src="js/chinaPro.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div style="width:1400px;height: 900px;margin:0 auto;background-image: url(img/beijing.png);text-align: center" >
        <div  style="margin-left: 70%;margin-bottom: -50px; width: 150px;height: 40px;background-color:#2c3343;border-radius:25px!important;padding-top: 10px;position:relative;z-index: 999">
            <button id="return" disabled style="background-image:url('img/return.png');background-color: #2c3343;background-repeat: no-repeat; width: 33px;height: 30px;border: 0px"></button>
            <div  class="input-append date" style="margin-left: 20px">
                <input type="text" id="dform3" class="ui_timepicker" style="display: none"/>
                <span class="add-on" style="width:40px; height: 40px;background-color: #2c3343;border: 0">
                    <button style="background-image:url('img/timeSelect.png');background-repeat: no-repeat; width: 25px;height: 25px;border: 0px;background-color: #2c3343;background-size:100%"></button>
                 </span>
            </div>
        </div>
    <div  style="margin-left: 85%;margin-bottom: -50px; width: 200px;height: 40px;background-color:#2c3343;border-radius:25px!important;padding-top: 10px;position:relative;z-index: 999">
        <img style="vertical-align:baseline" src="img/search.png" alt="">
        <input type="text" style="width: 150px;background-color: #2E3644;border: 0!important;color: #fff" onblur="inputOnblur()" />
    </div>
    <div style="margin-left: 80%;margin-bottom: -142px;margin-top:81px;height: 40px;position:relative;z-index: 999">
        <img src="img/dataTime.png" style="display: inline-block;margin-top: -3px">
        <p style="color: #ffffff;display: inline-block;margin-left: 10px" id="timeSelect"></p>
    </div>
    <div id="main"  style="width:1400px;height: 900px;position:relative;z-index: 0"></div>
</div>

<script type="text/javascript">
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    var a=new Date().Format("yyyy-MM-dd hh:mm:ss");
    $("#timeSelect").append(a);
    $('.input-append ').datetimepicker({
        format: 'yyyy-MM-dd hh:mm:ss',
        language: 'pt-BR'
    });
    $("input").focus(function(){
        $("input").css("background-color","#50586A");
    });
   function inputOnblur(){
       $("input").css("background-color","#2E3644")
    };
    $('.input-append').datetimepicker()
            .on('hide', function(ev){
                $("#timeSelect").html($('#dform3').val());
                }
            );
    $("#return").click(function(){
        $("#return").attr("disabled","disabled");
        $("#return").css("background-image","url(img/return.png)")
        lastData.geo={
            map: 'china',
            zoom: 1,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            roam:false,
            itemStyle: {
                normal: {
                    areaColor : '#43bff6',
                    borderColor: '#1c88da',
                    borderWidth:1,
                    opacity:0.9
                },
                emphasis: {
                    areaColor: '#086BAC'
                }
            },
            silent:false

        };
        for(var i=0;i<lastData.series.length;i++){
            if(lastData.series[i].type=='scatter'){
                lastData.series.splice(i,1);
                break
            }
        }
        lastData.series.push({
            type: 'scatter',
            coordinateSystem: 'geo',
            data: convertedData[0],
            symbolSize: 10,
            label: {
                normal: {
                    formatter: '{b}',
                    position: 'right',
                    show: false
                },
                emphasis: {
                    show: true
                }
            },
            itemStyle: {
                normal: {
                    color: '#fff'
                }
            }
        });
        if(lastData.series[0].data.length<=10){
            lastData.dataZoom=[
                { // 第二个 dataZoom 组件
                    show:false,
                    start: 0,
                    end: 100
                }
            ]
        }else{
            lastData.dataZoom=[
                { // 第二个 dataZoom 组件
                    show:true,
                    start:  lastData.series[0].data.length/data.length*85,
                    end: 100
                }
            ]
        }
        myChart.setOption(lastData);
    });
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    var markPoint=[];
    var markPoint2=[];
    // 指定图表的配置项和数据
    var categoryItem=[];
    var lastData=new Object();
    var convertedData2=[]
    var geoCoordMap = {
        "海门":[121.15,31.89],
        "鄂尔多斯":[109.781327,39.608266],
        "招远":[120.38,37.35],
        "舟山":[122.207216,29.985295],
        "齐齐哈尔":[123.97,47.33],
        "盐城":[120.13,33.38],
        "赤峰":[118.87,42.28],
        "青岛":[120.33,36.07],
        "乳山":[121.52,36.89],
        "金昌":[102.188043,38.520089],
        "泉州":[118.58,24.93],
        "莱西":[120.53,36.86],
        "日照":[119.46,35.42],
        "胶南":[119.97,35.88],
        "南通":[121.05,32.08],
        "拉萨":[91.11,29.97],
        "云浮":[112.02,22.93],
        "梅州":[116.1,24.55],
        "文登":[122.05,37.2],
        "上海":[121.48,31.22],
        "攀枝花":[101.718637,26.582347],
        "威海":[122.1,37.5],
        "承德":[117.93,40.97],
        "厦门":[118.1,24.46],
        "汕尾":[115.375279,22.786211],
        "潮州":[116.63,23.68],
        "丹东":[124.37,40.13],
        "太仓":[121.1,31.45],
        "曲靖":[103.79,25.51],
        "烟台":[121.39,37.52],
        "福州":[119.3,26.08],
        "瓦房店":[121.979603,39.627114],
        "即墨":[120.45,36.38],
        "抚顺":[123.97,41.97],
        "玉溪":[102.52,24.35],
        "张家口":[114.87,40.82],
        "阳泉":[113.57,37.85],
        "莱州":[119.942327,37.177017],
        "湖州":[120.1,30.86],
        "汕头":[116.69,23.39],
        "昆山":[120.95,31.39],
        "宁波":[121.56,29.86],
        "湛江":[110.359377,21.270708],
        "揭阳":[116.35,23.55],
        "荣成":[122.41,37.16],
        "连云港":[119.16,34.59],
        "葫芦岛":[120.836932,40.711052],
        "常熟":[120.74,31.64],
        "东莞":[113.75,23.04],
        "河源":[114.68,23.73],
        "淮安":[119.15,33.5],
        "泰州":[119.9,32.49],
        "南宁":[108.33,22.84],
        "营口":[122.18,40.65],
        "惠州":[114.4,23.09],
        "江阴":[120.26,31.91],
        "蓬莱":[120.75,37.8],
        "韶关":[113.62,24.84],
        "嘉峪关":[98.289152,39.77313],
        "广州":[113.23,23.16],
        "延安":[109.47,36.6],
        "太原":[112.53,37.87],
        "清远":[113.01,23.7],
        "中山":[113.38,22.52],
        "昆明":[102.73,25.04],
        "寿光":[118.73,36.86],
        "盘锦":[122.070714,41.119997],
        "长治":[113.08,36.18],
        "深圳":[114.07,22.62],
        "珠海":[113.52,22.3],
        "宿迁":[118.3,33.96],
        "咸阳":[108.72,34.36],
        "铜川":[109.11,35.09],
        "平度":[119.97,36.77],
        "佛山":[113.11,23.05],
        "海口":[110.35,20.02],
        "江门":[113.06,22.61]
    };

    var data = [
        {name: "海门", value: 9, province:"江苏"},
        {name: "鄂尔多斯", value: 12, province:"内蒙古"},
        {name: "招远", value: 12, province:"山东"},
        {name: "舟山", value: 12, province:"浙江"},
        {name: "齐齐哈尔", value: 14, province:"黑龙江"},
        {name: "盐城", value: 15, province:"江苏"},
        {name: "赤峰", value: 16, province:"内蒙古"},
        {name: "青岛", value: 18, province:"山东"},
        {name: "乳山", value: 18, province:"山东"},
        {name: "金昌", value: 19, province:"甘肃"},
        {name: "泉州", value: 21, province:"福建"},
        {name: "莱西", value: 21, province:"山东"},
        {name: "日照", value: 21, province:"山东"},
        {name: "胶南", value: 22, province:"山东"},
        {name: "南通", value: 23, province:"江苏"},
        {name: "拉萨", value: 24, province:"西藏"},
        {name: "云浮", value: 24, province:"广东"},
        {name: "梅州", value: 25, province:"广东"},
        {name: "文登", value: 25, province:"山东"},
        {name: "上海", value: 25, province:"上海"},
        {name: "攀枝花", value: 25, province:"四川"},
        {name: "威海", value: 25, province:"山东"},
        {name: "承德", value: 25, province:"河北"},
        {name: "厦门", value: 26, province:"福建"},
        {name: "汕尾", value: 26, province:"广东"},
        {name: "潮州", value: 26, province:"广东"},
        {name: "丹东", value: 27, province:"辽宁 "},
        {name: "太仓", value: 27, province:"江苏"},
        {name: "曲靖", value: 27, province:"云南"},
        {name: "烟台", value: 28, province:"山东"},
        {name: "福州", value: 29, province:"福建"},
        {name: "瓦房店", value: 30, province:"辽宁"},
        {name: "即墨", value: 30, province:"山东"},
        {name: "抚顺", value: 31, province:"辽宁"},
        {name: "玉溪", value: 31, province:"云南"},
        {name: "张家口", value: 31, province:"河北"},
        {name: "阳泉", value: 31, province:"山西"},
        {name: "莱州", value: 32, province:"山东"},
        {name: "湖州", value: 32, province:"浙江"},
        {name: "汕头", value: 32, province:"广东"},
        {name: "昆山", value: 33, province:"江苏"},
        {name: "宁波", value: 33, province:"浙江"},
        {name: "湛江", value: 33, province:"广州"},
        {name: "揭阳", value: 34, province:"广东"},
        {name: "荣成", value: 34, province:"山东"},
        {name: "连云港", value: 35, province:"江苏"},
        {name: "葫芦岛", value: 35, province:"辽宁"},
        {name: "常熟", value: 36, province:"江苏"},
        {name: "东莞", value: 36, province:"广东"},
        {name: "河源", value: 36, province:"广东"},
        {name: "淮安", value: 36, province:"江苏"},
        {name: "泰州", value: 36, province:"江苏"},
        {name: "南宁", value: 37, province:"广西"},
        {name: "营口", value: 37, province:"辽宁"},
        {name: "惠州", value: 37, province:"广东"},
        {name: "江阴", value: 37, province:"江苏"},
        {name: "蓬莱", value: 37, province:"山东"},
        {name: "韶关", value: 38, province:"广东"},
        {name: "嘉峪关", value: 38, province:"甘肃"},
        {name: "广州", value: 38, province:"广东"},
        {name: "延安", value: 38, province:"陕西"},
        {name: "太原", value: 39, province:"山西"},
        {name: "清远", value: 39, province:"广东"},
        {name: "中山", value: 39, province:"广东"},
        {name: "昆明", value: 39, province:"云南"},
        {name: "寿光", value: 40, province:"山东"},
        {name: "盘锦", value: 40, province:"辽宁"},
        {name: "长治", value: 41, province:"山西"},
        {name: "深圳", value: 41, province:"深圳"},
        {name: "珠海", value: 42, province:"广东"},
        {name: "宿迁", value: 43, province:"江苏"},
        {name: "咸阳", value: 43, province:"陕西"},
        {name: "铜川", value: 44, province:"陕西"},
        {name: "平度", value: 44, province:"山东"},
        {name: "佛山", value: 44, province:"广东"},
        {name: "海口", value: 44, province:"海南"},
        {name: "江门", value: 45, province:"广东"}
    ];

    var convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            }
        }
        return res;
    };

    var convertedData = [
        convertData(data),
        convertData(data.sort(function (a, b) {
            return b.value - a.value;
        }).slice(0, 6))
    ];


    option = {
        title: [
/*            {
                text: '全国主要城市 PM 2.5',
                subtext: 'data from PM25.in',
                sublink: 'http://www.pm25.in',
                left: 'center',
                textStyle: {
                    color: '#fff'
                }
            },*/
            {
                id: 'statistic',
                right: 250,
                top: 100,
                width: 100,
                textStyle: {
                    color: '#fff',
                    fontSize: 16
                }
            },
            {
                id:'visualMap',
                left: 125,
                top: 100,
                textStyle: {
                    color: '#fff',
                    fontSize: 14
                }
            },
            {
                id:'subscribe',
                right: 43,
                top: 130,
                textStyle: {
                    color: '#fff',
                    fontSize: 14
                }
            }
        ],
        toolbox:{
            show:false
        },
        visualMap: {
            id:'visualMap',
            type: 'continuous',
            min: 0,
            max: 100,
            align:'bottom',
            orient:'horizontal',
            realtime: false,
            calculable : true,
            seriesIndex:[0],
            left:20,
            top:70,
            target: {
                inRange: {
                    color: ['#fff']
                }
            },
            controller: {
                inRange: {
                    color: ['#2193EC']
                }
            },
            itemWidth:15,
            itemHeight:200,
            textStyle:{
                color:'#fff'
            },
            formatter:function (value) {
                return  value<10?"    "+value.toFixed(2)+"%":value<100?"  "+value.toFixed(2)+"%":value.toFixed(2)+"%"; // 范围标签显示内容。
            }
        },
        brush: {
            outOfBrush: {
                color: '#abc'
            },
            brushStyle: {
                borderWidth: 2,
                color: 'rgba(0,0,0,0.2)',
                borderColor: 'rgba(0,0,0,0.5)',
            },
            seriesIndex: [0, 1],
            throttleType: 'debounce',
            throttleDelay: 300,
            geoIndex: 0
        },
        geo: {
            map: 'china',
            left: '10',
            right: '35%',
            zoom: 1,
            label: {
                normal: {
                    show: true,
                    textStyle:{
                        color:"#fff"
                    }
                },
                emphasis: {
                    show: true,
                    textStyle:{
                        color:"#fff"
                    }
                }
            },
            roam: false,
            itemStyle: {
                normal: {
                    areaColor : '#43bff6',
                    borderColor: '#1c88da',
                    borderWidth:1,
                    opacity:0.9
                },
                emphasis: {
                    areaColor: '#086BAC'
                }
            }
        },
        tooltip : {
            trigger: 'item',
            formatter:function (params) {
                if(params.componentSubType=="scatter"){
                    return params.value!=null?params.name+":"+params.value+"<br />采集完整率："+params.value[2]+"%" :null;
                }else if(params.componentSubType=="bar"){
                    return params.value!=null?params.name+":"+params.value+"%":null;
                }
            }
        },
        grid: {
            right: 100,
            top: 150,
            bottom: 40,
            width: '20%',
            height:'70%'
        },
        xAxis: {
            type: 'value',
            position: 'top',
            splitLine: {show: false},
            axisLine: {show: false},
            axisTick: {show: false},
            axisLabel: {margin: 2, textStyle: {color: '#aaa'}},
        },
        yAxis: {
            type: 'category',
            nameGap: 16,
            axisLine: {show: false, lineStyle: {color: '#ddd'}},
            axisTick: {show: false, lineStyle: {color: '#ddd'}},
            axisLabel: {interval: 0, textStyle: {color: '#ddd'}},
            data: []
        },
        dataZoom: [
            { // 第二个 dataZoom 组件
                type: 'slider',
                show: true,
                yAxisIndex: 0,
                zoomLock:true,
                filterMode: 'empty',
                showDetail:false,
                width: 20,
                height: '70%',
                handleSize:0,
                start: 85,
                end: 100,
                showDataShadow: false,
                left: '97%',
                textStyle:{
                    color:'#fff'
                }
/*                labelFormatter: function (value) {
                    if(!isNaN(value)){
                        return data[value].value+'%';
                    }

                }*/
            }
        ],
        series : [
            {
                type: 'scatter',
                coordinateSystem: 'geo',
                data: convertedData[0],
                symbolSize: 15,
                hoverAnimation:true,
                label: {
                    normal: {
                        formatter: '{b}',
                        position: 'right',
                        show: false
                    },
                    emphasis: {
                        show: true,
                        textStyle:{
                            fontSize:20
                        }

                    }
                },
                itemStyle: {
                    normal: {
                        color: '#fff'
                    },
                    emphasis: {
                        show: true,

                    }
                }
            },
            {
                id: 'bar2',
                type: 'bar',
                animationDurationUpdate:0,
                animationEasingUpdate:"elasticInOut",
                symbol: 'none',
                itemStyle: {
                    normal: {
                        color: '#50576A'
                    }
                },
                silent: true,
                barGap: '-100%', // Make series be overlap
                zlevel: 1,
                markPoint:{
                    //symbol:'image://img/starYellow.png',
                    symbolSize:20,
                    symbolOffset:['80%', '0%'],
                    label:{
                        normal:{
                            show:false
                        }
                    },
                    data: []
                },
                data: []
            },
            {
                id: 'bar',
                zlevel: 99,
                animationDurationUpdate:0,
                animationEasingUpdate:"elasticInOut",
                type: 'bar',
                symbol: 'none',
                itemStyle: {
                    normal: {
                        color: '#2193EC'
                    }
                },
                markPoint:{
                    //symbol:'image://img/starGray.png',
                    symbolSize:20,
                    symbolOffset:['200%', '0%'],
                    label:{
                        normal:{
                            show:false
                        }
                    },
                    data : []
                },
                data: []
            },
            {
                type: 'scatter',
                coordinateSystem: 'geo',
                data:convertedData2,
                symbolSize: 15,
                hoverAnimation:true,
                label: {
                    normal: {
                        formatter: '{b}',
                        position: 'right',
                        show: false
                    },
                    emphasis: {
                        show: true,
                        textStyle:{
                            fontSize:20
                        }

                    }
                },
                itemStyle: {
                    normal: {
                        color: '#fff'
                    },
                    emphasis: {
                        show: true,

                    }
                }
            }
        ]
    };


    myChart.on('datarangeselected', renderBrushed);
    myChart.on('click', handleClick);
    myChart.on('mouseover', handleOver);
    myChart.on('mouseout', handleOut);
    function handleOver(params){
        myChart.dispatchAction({
            type: 'highlight',
            seriesIndex:[0,1,2,3],
            name:params.name
        })
    }
    function handleOut(params){
        myChart.dispatchAction({
            type: 'downplay',
            seriesIndex:[0,1,2,3],
            name:params.name
        })
    }
    // myChart.setOption(option);
/*    setTimeout(function () {
        myChart.dispatchAction({
            type: 'brush',
            areas: [
                {
                    geoIndex: 0,
                    brushType: 'polygon',
                    coordRange: [[119.72,34.85],[119.68,34.85],[119.5,34.84],[119.19,34.77],[118.76,34.63],[118.6,34.6],[118.46,34.6],[118.33,34.57],[118.05,34.56],[117.6,34.56],[117.41,34.56],[117.25,34.56],[117.11,34.56],[117.02,34.56],[117,34.56],[116.94,34.56],[116.94,34.55],[116.9,34.5],[116.88,34.44],[116.88,34.37],[116.88,34.33],[116.88,34.24],[116.92,34.15],[116.98,34.09],[117.05,34.06],[117.19,33.96],[117.29,33.9],[117.43,33.8],[117.49,33.75],[117.54,33.68],[117.6,33.65],[117.62,33.61],[117.64,33.59],[117.68,33.58],[117.7,33.52],[117.74,33.5],[117.74,33.46],[117.8,33.44],[117.82,33.41],[117.86,33.37],[117.9,33.3],[117.9,33.28],[117.9,33.27],[118.09,32.97],[118.21,32.7],[118.29,32.56],[118.31,32.5],[118.35,32.46],[118.35,32.42],[118.35,32.36],[118.35,32.34],[118.37,32.24],[118.37,32.14],[118.37,32.09],[118.44,32.05],[118.46,32.01],[118.54,31.98],[118.6,31.93],[118.68,31.86],[118.72,31.8],[118.74,31.78],[118.76,31.74],[118.78,31.7],[118.82,31.64],[118.82,31.62],[118.86,31.58],[118.86,31.55],[118.88,31.54],[118.88,31.52],[118.9,31.51],[118.91,31.48],[118.93,31.43],[118.95,31.4],[118.97,31.39],[118.97,31.37],[118.97,31.34],[118.97,31.27],[118.97,31.21],[118.97,31.17],[118.97,31.12],[118.97,31.02],[118.97,30.93],[118.97,30.87],[118.97,30.85],[118.95,30.8],[118.95,30.77],[118.95,30.76],[118.93,30.7],[118.91,30.63],[118.91,30.61],[118.91,30.6],[118.9,30.6],[118.88,30.54],[118.88,30.51],[118.86,30.51],[118.86,30.46],[118.72,30.18],[118.68,30.1],[118.66,30.07],[118.62,29.91],[118.56,29.73],[118.52,29.63],[118.48,29.51],[118.44,29.42],[118.44,29.32],[118.43,29.19],[118.43,29.14],[118.43,29.08],[118.44,29.05],[118.46,29.05],[118.6,28.95],[118.64,28.94],[119.07,28.51],[119.25,28.41],[119.36,28.28],[119.46,28.19],[119.54,28.13],[119.66,28.03],[119.78,28],[119.87,27.94],[120.03,27.86],[120.17,27.79],[120.23,27.76],[120.3,27.72],[120.42,27.66],[120.52,27.64],[120.58,27.63],[120.64,27.63],[120.77,27.63],[120.89,27.61],[120.97,27.6],[121.07,27.59],[121.15,27.59],[121.28,27.59],[121.38,27.61],[121.56,27.73],[121.73,27.89],[122.03,28.2],[122.3,28.5],[122.46,28.72],[122.5,28.77],[122.54,28.82],[122.56,28.82],[122.58,28.85],[122.6,28.86],[122.61,28.91],[122.71,29.02],[122.73,29.08],[122.93,29.44],[122.99,29.54],[123.03,29.66],[123.05,29.73],[123.16,29.92],[123.24,30.02],[123.28,30.13],[123.32,30.29],[123.36,30.36],[123.36,30.55],[123.36,30.74],[123.36,31.05],[123.36,31.14],[123.36,31.26],[123.38,31.42],[123.46,31.74],[123.48,31.83],[123.48,31.95],[123.46,32.09],[123.34,32.25],[123.22,32.39],[123.12,32.46],[123.07,32.48],[123.05,32.49],[122.97,32.53],[122.91,32.59],[122.83,32.81],[122.77,32.87],[122.71,32.9],[122.56,32.97],[122.38,33.05],[122.3,33.12],[122.26,33.15],[122.22,33.21],[122.22,33.3],[122.22,33.39],[122.18,33.44],[122.07,33.56],[121.99,33.69],[121.89,33.78],[121.69,34.02],[121.66,34.05],[121.64,34.08]]
                }
            ]
        });series-scatter.geoIndex
    }, 0);*/
function handleClick(params) {
    markPoint=myChart.getOption().series[2].markPoint.data;
    markPoint2=myChart.getOption().series[1].markPoint.data;
    var dataItem=[];
    categoryItem=[];
    var name=params.name;

    if(params.componentType=="geo"){
        handleClickGeo(params);
    }
    if(params.componentType=="series"||params.componentType=="bar"){
        window.location.href="index3.html?id="+encodeURI(params.name);
    }else{
        if(params.componentType!="markPoint"){
            return
        }
    }
    convertedData2=[];
    for(var i=0;i<markPoint.length;i++){
        if(markPoint[i].yAxis==params.data.yAxis){
            if(markPoint[i].symbol=='image://img/starGray.png'){
                markPoint2.push(markPoint[i]);
                markPoint[i].symbol='image://img/starYellow.png';
                for(var k=0;k<data.length;k++){
                    for(var j=0;j<markPoint2.length;j++){
                        if(data[k].name==markPoint2[j].yAxis){
                            data.splice(k,1);
                            k=k-1;
                        }
                    }
                }
                for(var m=0;m<data.length;m++){
                    dataItem.push(data[m].value);
                    categoryItem.push(data[m].name);
                }
                for(var n=0;n<markPoint2.length;n++){
                    dataItem.push(markPoint2[n].value);
                    categoryItem.push(markPoint2[n].yAxis);
                    for(var c=0;c<convertedData[0].length;c++){
                        if(markPoint2[n].yAxis==convertedData[0][c].name){
                            convertedData2.push(convertedData[0][c]);
                        }
                    }
                }
            }else{
                for(var j=0;j<markPoint.length;j++){
                    if(markPoint[j].yAxis==params.data.yAxis){
                        data.push(
                                {
                                    name: markPoint[j].yAxis,
                                    value:markPoint[j].value,
                                    province:markPoint[j].province
                                }
                        );
                        data.sort(function (a, b) {
                            return a.value - b.value;
                        });
                        for(var c=0;c<markPoint2.length;c++){
                            if(markPoint2[c].yAxis==params.data.yAxis){
                                markPoint2.splice(c,1);
                            }
                        }
                        categoryItem=[];
                        dataItem=[];
                        for(var m=0;m<data.length;m++){
                            categoryItem.push(data[m].name);
                            dataItem.push(data[m].value);
                        }
                        for(var n=0;n<markPoint2.length;n++){
                            categoryItem.push(markPoint2[n].yAxis);
                            dataItem.push(markPoint2[n].value);
                            for(var c=0;c<convertedData[0].length;c++){
                                if(markPoint2[n].yAxis==convertedData[0][c].name){
                                    convertedData2.push(convertedData[0][c]);
                                }
                            }
                        }
                    }
                }
                markPoint[i].symbol='image://img/starGray.png';
            }
        }
    };
    var chartObject=new Object();

       chartObject={
           yAxis: {
               data: categoryItem
           },
           series: [
               {
                   type: 'scatter',
                   coordinateSystem: 'geo',
                   data: convertedData[0]
               },
               {
               id: 'bar',
               data: dataItem,
               markPoint:{
                   data:markPoint
                   }
           },{
               id: 'bar2',
               markPoint:{
                   data:markPoint2
               }
           }, {
                   type: 'scatter',
                   coordinateSystem: 'geo',
                   data: convertedData2
               },
           ]
       };
    myChart.setOption(chartObject);
    var params={
        type:'datarangeselected',
        selected:myChart.getOption().visualMap[0].range
    };
    renderBrushed(params);
    if(myChart.getOption().geo[0].map!="china"){
         var params={
         name:myChart.getOption().geo[0].map,
             componentType:"geo"
         };
         handleClick(params)
     }
}
    function renderBrushed(params) {
        var selectedItems = [];
        var barData = [];
        var barData2 = [];
        var sum = 0;
        var count = 0;
        var chartObject=new Object();
        var categoryData=[];
        if(params==null){
            for(var j=0;j<data.length;j++){
                sum+=data[j].value;
            }
            selectedItems=data;
            count=data.length;
            selectedItems.sort(function (a, b) {
                return a.value - b.value;
            });
            for (var i = 0; i < selectedItems.length; i++) {
                var markObject=new Object();
                categoryData.push(selectedItems[i].name);
                barData.push(selectedItems[i].value);
                barData2.push(100);
                markObject.value=selectedItems[i].value;
                markObject.xAxis=100;
                markObject.yAxis=selectedItems[i].name;
                markObject.province=selectedItems[i].province;
                markObject.symbol='image://img/starGray.png';
                markPoint.push(markObject);

            }
        } else if(params.type=='datarangeselected'){
            var templeData=[];
            markPoint=[];
            for(var j=0;j<data.length;j++){
                if(data[j].value>=params.selected[0]&&data[j].value<=params.selected[1]){
                    var templeObject=new Object();
                    var markObject=new Object();
                    templeObject.name=data[j].name;
                    templeObject.value=data[j].value;
                    templeData.push(templeObject);
                    markObject.value=data[j].value;
                    markObject.province=data[j].province;
                    markObject.xAxis=100;
                    markObject.yAxis=data[j].name;
                    markObject.symbol='image://img/starGray.png';
                    markPoint.push(markObject);
                }
            }
            templeData.sort(function (a, b) {
                return a.value - b.value;
            });
            for(var m=0;m<markPoint2.length;m++){
                templeData.push(
                        {
                            name:markPoint2[m].yAxis,
                            value:markPoint2[m].value
                        }
                );
                markPoint.push(
                        {
                            value:markPoint2[m].value,
                            province:markPoint2[m].province,
                            xAxis:100,
                            yAxis:markPoint2[m].yAxis,
                            symbol:'image://img/starYellow.png'
                        }
                )
            }
            count=templeData.length;

            for (var i = 0; i < templeData.length; i++) {
                categoryData.push(templeData[i].name);
                barData.push(templeData[i].value);
                barData2.push(100);
            }
        }

        chartObject={
            yAxis: {
                data: categoryData
            },
            xAxis: {
                axisLabel: {show: !!count,formatter:'{value} %'}
            },
            title: [
                {
                    id: 'statistic',
                    text: '全国主要监测项目'
                },
                {
                    id: 'visualMap',
                    text: '数据采集完整率过滤'
                },
                {
                    id:'subscribe',
                    text: '订阅'
                }
            ],
            series: [{
                id: 'bar',
                data: barData,
                markPoint:{
                    data:markPoint
                }
            },{
                id: 'bar2',
                data: barData2,
                markPoint:{
                    data:markPoint2
                }
            }]
        };
        if(params!=null){
            if(params.type=='datarangeselected'){
                if(barData.length<=10){
                    chartObject.dataZoom=[
                        { // 第二个 dataZoom 组件
                            show:false,
                            start: 0,
                            end: 100
                        }
                    ]
                }else {
                    chartObject.dataZoom=[
                        { // 第二个 dataZoom 组件
                            show:true,
                            start: barData.length/data.length*85,
                            end: 100
                        }
                    ]
                }
            }
        }
        console.log(barData.length/data.length*85);
        lastData=chartObject;
        myChart.setOption(chartObject);
        if(myChart.getOption().geo[0].map!="china"){
            var params={
                name:myChart.getOption().geo[0].map,
                componentType:"geo"
            };
            handleClick(params)
        }
    }

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    renderBrushed();
    Array.prototype.clone = function () {
        return this.slice(0);
    };

    function handleClickGeo(params){
        var dataItem=[];
        $("#return").removeAttr("disabled");
        $("#return").css("background-image","url(img/returnWhite.png)");

        var chartObject=new Object();
        var scatterArray=convertedData[0];
        var markpointT1=[];
        var markpointT2=[];
        var barData=[];
        var barData2=[];
        for(var i=0;i<markPoint.length;i++){
            if(markPoint[i].province==params.name){
                markpointT1.push(markPoint[i]);
                barData.push(markPoint[i].value);
                barData2.push(100);
                categoryItem.push(markPoint[i].yAxis)
            }
        };
        for(var j=0;j<markPoint2.length;j++){
            if(markPoint2[j].province==params.name){
                markpointT2.push(markPoint2[j]);
            }
        }
        for(var k=0;k<convertedData[0].length;k++){
            if($.inArray(convertedData[0][k].name,categoryItem)!=-1){
                dataItem.push(convertedData[0][k])
            }
        }
        chartObject={
            title:[
                {
                    id: 'statistic',
                    text: params.name+'主要监测项目'
                }
            ],
            yAxis: {
                data: categoryItem
            },
            geo: {
                map: params.name,
                layoutCenter: ['35%', '50%'],
// 如果宽高比大于 1 则宽度为 100，如果小于 1 则高度为 100，保证了不超过 100x100 的区域
                layoutSize: 800,
                zoom: 0.9,
                label: {
                    normal: {
                        show: true
                    },
                    emphasis: {
                        show: true
                    }
                },
                roam:false,
                itemStyle: {
                    normal: {
                        areaColor : '#43bff6',
                        borderColor: '#1c88da',
                        borderWidth:1,
                        opacity:0.9
                    },
                    emphasis: {
                        areaColor: '#086BAC'
                    }
                },
                silent:true
            },
            series: [
                {
                    type: 'scatter',
                    coordinateSystem: 'geo',
                    data: dataItem
                },
                {
                    id: 'bar',
                    data: barData,
                    markPoint:{
                        data:markpointT1
                    }
                },{
                    id: 'bar2',
                    data: barData2,
                    markPoint:{
                        data:markpointT2
                    }
                }]
        };
        if(barData.length<=10){
            chartObject.dataZoom=[
                { // 第二个 dataZoom 组件
                    show:false,
                    start: 0,
                    end: 100
                }
            ]
        }else{
            chartObject.dataZoom=[
                { // 第二个 dataZoom 组件
                    show:true,
                    start: barData.length/data.length*85,
                    end: 100
                }
            ]
        }
        myChart.setOption(chartObject);
    }
</script>
</body>
</html>